package cn.redcoral.messageplus.handler;

import cn.messageplus.core.implement.MessageRequestHandlerImpl;
import cn.messageplus.core.message.request.parent.MessageRequest;
import cn.redcoral.messageplus.data.service.HistoryMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Slf4j
@Configuration
public class RequestHandler implements MessageRequestHandlerImpl {
    @Resource
    private HistoryMessageService historyMessageService;

    @Override
    public boolean handlerResponse(MessageRequest request) {
//        log.info("拦截到请求");
        short type = request.getType();
        if (type==4||type==5) {
            // 音频、图片等大文件请求不处理
        } else {
            String s = historyMessageService.insertMessage(request);
            if (s == null) {
                log.error("消息持久化失败！");
                return false;
            }
        }
        return true;
    }
}
